﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true"
    CodeFile="EditUsers.aspx.cs" Inherits="Users_EditUsers" Title="Потребители" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <h2 style="border-bottom: solid 1px black">
        <asp:Image ID="imgUsers" runat="server" Width="15" Height="15" ImageUrl="~/images/Profile.png" />&nbsp;&nbsp;Потребители
        на системата</h2>
    <asp:UpdatePanel ID="upUsers" runat="server">
        <ContentTemplate>
            <asp:MultiView ID="mvEditUsers" runat="server">
                <asp:View ID="vUsersList" runat="server">
                    <asp:HiddenField ID="hfUserName" runat="server" />
                    <asp:GridView ID="gvUsers" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="odsUsers"
                        GridLines="Horizontal" DataKeyNames="UserName">
                        <HeaderStyle BackColor="#d2f1ad" />
                        <RowStyle CssClass="grid_hover" />
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:ImageButton ID="ibtnEditUser" Style="vertical-align: middle;" AlternateText="Редакция на потребител"
                                        OnCommand="ibtnEditUser_Command" CommandArgument='<%# Eval("UserName") %>' runat="server"
                                        ImageUrl="~/images/Modify.png" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="UserName" HeaderText="Име" ReadOnly="True" SortExpression="UserName" />
                            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                            <asp:BoundField DataField="LastLoginDate" HeaderText="Последно посещение" SortExpression="LastLoginDate" />
                        </Columns>
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:GridView>
                    <asp:ObjectDataSource ID="odsUsers" runat="server" TypeName="System.Web.Security.Membership"
                        OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllUsers"></asp:ObjectDataSource>
                    <p style="margin-top: 8px;">
                        <asp:HyperLink ID="lbtnAddUser" CssClass="link" NavigateUrl="~/Users/CreateUser.aspx"
                            runat="server">
                            <asp:Image ID="imgAddUser" AlternateText="Нов потребител" ImageAlign="Left" runat="server"
                                ImageUrl="~/images/Add.png" />
                            Нов потребител</asp:HyperLink>
                    </p>
                </asp:View>
                <asp:View ID="vUserInfo" runat="server">
                    <asp:DetailsView ID="dvUserInfo" runat="server" OnItemUpdating="dvUserInfo_ItemUpdating"
                        AutoGenerateRows="False" DataSourceID="odsProfile" CellPadding="3" Width="400px"
                        DataKeyNames="UserName">
                        <FieldHeaderStyle Width="100px" />
                        <HeaderStyle BackColor="#D2F1AD" Font-Bold="True" />
                        <HeaderTemplate>
                            <label style="float: left;" class="insert_label">
                                <b>Данни за потребителя</b></label><asp:ImageButton ID="ibtnClose" Style="float: right;"
                                    ImageUrl="~/images/Delete.png" ToolTip="Затвори" Width="20" runat="server" CausesValidation="false"
                                    OnClick="ibtnClose_Click" />
                        </HeaderTemplate>
                        <Fields>
                            <asp:TemplateField HeaderText="Акаунт" SortExpression="UserName">
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Email">
                                <ItemTemplate>
                                    <asp:Label ID="lblEmail" runat="server" Text='<%# GetEmailForUser(Eval("UserName").ToString()) %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbEmail" MaxLength="256" Width="250" ValidationGroup="UserInfo" Text='<%# GetEmailForUser(Eval("UserName").ToString()) %>'
                                        runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="rfvEmail" ValidationGroup="UserInfo" runat="server"
                                        ControlToValidate="tbEmail" Display="Dynamic" ToolTip='Полето "Email" е задължително!'>*</asp:RequiredFieldValidator><asp:RegularExpressionValidator
                                            ID="revEmail" runat="server" ControlToValidate="tbEmail" Display="Dynamic" ErrorMessage="Полето &quot;Email&quot; не е коректно!"
                                            ToolTip="Полето &quot;Email&quot; не е коректно!" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                            ValidationGroup="UserInfo">*</asp:RegularExpressionValidator>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Име" SortExpression="FirstName">
                                <ItemTemplate>
                                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbFirstName" Width="250" MaxLength="30" runat="server" ValidationGroup="UserInfo"
                                        Text='<%# Bind("FirstName") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="rfvFirstName" ValidationGroup="UserInfo" runat="server"
                                        ControlToValidate="tbFirstName" Display="Dynamic" ToolTip='Полето "Име" е задължително!'>*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Презиме" SortExpression="MiddleName">
                                <ItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("MiddleName") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbMiddleName" Width="250" MaxLength="30" runat="server" ValidationGroup="UserInfo"
                                        Text='<%# Bind("MiddleName") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="rfvMiddleName" ValidationGroup="UserInfo" runat="server"
                                        ControlToValidate="tbMiddleName" Display="Dynamic" ToolTip='Полето "Презиме" е задължително!'>*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Фамилия" SortExpression="LastName">
                                <ItemTemplate>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbLastName" Width="250" MaxLength="30" runat="server" ValidationGroup="UserInfo"
                                        Text='<%# Bind("LastName") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="rfvLastName" ValidationGroup="UserInfo" runat="server"
                                        ControlToValidate="tbLastName" Display="Dynamic" ToolTip='Полето "Фамилия" е задължително!'>*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Възраст" SortExpression="Age">
                                <ItemTemplate>
                                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Age") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbAge" Width="250" MaxLength="2" runat="server" ValidationGroup="UserInfo" Text='<%# Bind("Age") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="rfvAge" ValidationGroup="UserInfo" runat="server"
                                        ControlToValidate="tbAge" Display="Dynamic" ToolTip='Полето "Възраст" е задължително!'>*</asp:RequiredFieldValidator><asp:CompareValidator
                                            ID="revAge" runat="server" ControlToValidate="tbAge" Display="Dynamic" ErrorMessage="Полето &quot;Възраст&quot; не е коректно!"
                                            Operator="GreaterThan" ToolTip="Полето &quot;Възраст&quot; не е коректно!" Type="Integer"
                                            ValidationGroup="UserInfo" ValueToCompare="15">*</asp:CompareValidator>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Пол" SortExpression="Sex">
                                <ItemTemplate>
                                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("Sex") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="ddlSex" runat="server" SelectedValue='<%# Bind("Sex") %>'>
                                        <asp:ListItem Text="Male" Value="Male"></asp:ListItem>
                                        <asp:ListItem Text="Female" Value="Female"></asp:ListItem>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Адрес" SortExpression="Address">
                                <ItemTemplate>
                                    <asp:Label ID="Label7" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbAddress"  MaxLength="80" Width="250" runat="server" ValidationGroup="UserInfo"
                                        Text='<%# Bind("Address") %>'></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="rfvAddress" ValidationGroup="UserInfo" runat="server"
                                        ControlToValidate="tbAddress" Display="Dynamic" ToolTip='Полето "Адрес" е задължително!'>*</asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Мобилен тел." SortExpression="MobilePhone">
                                <ItemTemplate>
                                    <asp:Label ID="Label8" runat="server" Text='<%# Bind("MobilePhone") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox7" MaxLength="25" Width="250" runat="server" Text='<%# Bind("MobilePhone") %>'></asp:TextBox>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Телефон" SortExpression="Phone">
                                <ItemTemplate>
                                    <asp:Label ID="Label9" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox8" Width="250" MaxLength="25" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                                </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False">
                                <ItemTemplate>
                                    <div style="float: right;">
                                        <asp:Button ID="btnEdit" ValidationGroup="UserInfo" runat="server" CausesValidation="False"
                                            CommandName="Edit" Text="Редактирай" />
                                        <asp:Button ID="btnDelete" ValidationGroup="UserInfo" OnClientClick='javascript:return confirm("Сигурни ли сте, че искате да изтриете този потребител?");'
                                            CommandArgument='<%# Eval("UserName") %>' CommandName="DeleteUser" OnCommand="btnDelete_Command"
                                            runat="server" CausesValidation="False" Text="Изтрий" />
                                    </div>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <div style="float: right;">
                                        <asp:Button ID="btnUpdate" ValidationGroup="UserInfo" runat="server" CausesValidation="True"
                                            CommandName="Update" Text="Обнови" />
                                        &nbsp;<asp:Button ID="lbtnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Отказ" />
                                    </div>
                                </EditItemTemplate>
                            </asp:TemplateField>
                        </Fields>
                    </asp:DetailsView>
                    <asp:ObjectDataSource ID="odsProfile" runat="server" SelectMethod="GetProfile" TypeName="ProfileCommon">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="hfUserName" Name="username" PropertyName="Value"
                                Type="String" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                </asp:View>
            </asp:MultiView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
